//
//  LJFHomeController.m
//  SevenZhou
//
//  Created by qianfeng on 15/9/14.
//  Copyright (c) 2015年 ljf. All rights reserved.
//

#import "LJFHomeController.h"
#import "LJFCustom1Cell.h"
#import "LJFCustom2Cell.h"
#import "LJFHttpManager.h"
#import "LJFSubjects.h"
#import "UIImageView+AFNetworking.h"

@interface LJFHomeController ()<UITableViewDataSource,UITableViewDelegate>
{
    NSMutableArray *_dataArr;
}

@property (weak, nonatomic) IBOutlet UITableView *myTableView;


@end

@implementation LJFHomeController

- (instancetype)initWithCoder:(NSCoder *)coder
{
    self = [super initWithCoder:coder];
    if (self) {
        _dataArr =[[NSMutableArray alloc] init];
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    [self loadSevenZhouDataFromNet];
}

- (void)loadSevenZhouDataFromNet
{
    LJFHttpManager *manager = [LJFHttpManager shareInstance];
    
    [manager getDataFromNetWithUrl:URL_HomeSevenZhou AndParameterStr:URL_HomeSevenZhou_parameter success:^(id responseObj)
    {
       // NSLog(@"responseObj == %@",responseObj);
        
        NSDictionary *dict = responseObj;
        
        for (NSDictionary *dic in dict[@"data"])
        {
            LJFSubjects *model = [[LJFSubjects alloc] initWithNsdictaryion:dic];
            
            [_dataArr addObject:model];
        }
        [self.myTableView reloadData];
        
    } failure:^(NSError *error)
    {
        NSLog(@"error == %@",error);
    }];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

#pragma mark -UITableViewDataSource,UITableViewDelegate

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if (section == 0)
    {
        return 1;
    }
    else
    {
        return _dataArr.count;
    }
}

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 2;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{

    if (indexPath.section == 0)
    {
        LJFCustom1Cell *cell = [tableView dequeueReusableCellWithIdentifier:@"LJFCustom1Cell" forIndexPath:indexPath];
        return cell;
    }
    else
    {
        LJFSubjects *model = _dataArr[indexPath.row];
        
        LJFCustom2Cell *cell = [tableView dequeueReusableCellWithIdentifier:@"LJFCustom2Cell"];
        
        cell.myTitle.text = [NSString stringWithFormat:@"#%@#",model.class_title];
        cell.myContents.text = model.class_text;
        
        [cell.imgView1 setImageWithURL:[NSURL URLWithString:[model.goods_list[0] goods_img]]];
        [cell.imgView2 setImageWithURL:[NSURL URLWithString:[model.goods_list[1] goods_img]]];
        [cell.imgview3 setImageWithURL:[NSURL URLWithString:[model.goods_list[2] goods_img]]];
        [cell.imgView4 setImageWithURL:[NSURL URLWithString:[model.goods_list[3] goods_img]]];
        [cell.imgView5 setImageWithURL:[NSURL URLWithString:[model.goods_list[4] goods_img]]];
        [cell.imgView6 setImageWithURL:[NSURL URLWithString:[model.goods_list[5] goods_img]]];
        [cell.imgView7 setImageWithURL:[NSURL URLWithString:[model.goods_list[6] goods_img]]];
        [cell.imgView8 setImageWithURL:[NSURL URLWithString:[model.goods_list[7] goods_img]]];
        
        cell.label1.text = [model.goods_list[0] name];
        cell.label2.text = [model.goods_list[1] name];
        cell.label3.text = [model.goods_list[2] name];
        cell.label4.text = [model.goods_list[3] name];
        cell.label5.text = [model.goods_list[4] name];
        cell.label6.text = [model.goods_list[5] name];
        cell.label7.text = [model.goods_list[6] name];
        cell.label8.text = [model.goods_list[7] name];
        
        return cell;
    }
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section == 0)
    {
        return 183;
    }
    else
    {
        return 290;
    }
}


@end
